package com.buba.appointment.controller;


import org.springframework.web.bind.annotation.*;
import com.buba.appointment.service.MedicalAppointmentService;
import com.buba.appointment.vo.MedicalAppointmentVo;
import com.buba.pojo.record.Convention;
import com.buba.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.buba.appointment.service.impl.MedicalAppointmentServiceImpl;
import com.buba.pojo.appointment.MedicalAppointment;
import com.buba.pojo.record.Record;
import com.buba.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 体检预约表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-06-09
 */

@RestController
@RequestMapping("/appointment/medical-appointment")
@Slf4j
public class MedicalAppointmentController {

    @Autowired
    private MedicalAppointmentService medicalAppointmentService;

    //查询体检详情
    @GetMapping("/medicaDetails/{id}")
    public R medicaDetails(@PathVariable Integer id){
        MedicalAppointmentVo medicalAppointmentVo = medicalAppointmentService.medicaDetails(id);
        return R.ok().data("details" , medicalAppointmentVo);
    }

    //根据就诊人查询体检记录体检记录
    @GetMapping("/medicalRecord/{id}/{begin}/{end}")
    public R medicalRecord(@PathVariable Integer id , @PathVariable String begin , @PathVariable String end){
        List<MedicalAppointmentVo> medicalAppointmentVos = medicalAppointmentService.medicalRecord(id , begin , end);
        return R.ok().data("medical" , medicalAppointmentVos);
    }

    /*
     * @Author: 张庆威
     * @Description: (生成)
     * @Date: 20:33 2022/6/21
     * @Param: [medicalAppointment]
     * @return: com.buba.utils.R
     **/
    @RequestMapping(value = "/addtijian",method = RequestMethod.POST)
    public R addtijian(@RequestBody MedicalAppointment medicalAppointment){

        medicalAppointment.setCampusId(1);
        medicalAppointment.setState("未完成");
        medicalAppointment.setCreateTime(new Date());
        medicalAppointment.setUpdateTime(new Date());
        medicalAppointment.setDepartmentId(43);
        boolean save = medicalAppointmentService.save(medicalAppointment);
        if(save == true){
            return R.ok();
        }else{
            return R.error();
        }
    }

    @PostMapping("/updatetjState")
    public R updatetjState(@RequestBody MedicalAppointment medicalAppointment){
        medicalAppointment.setState("已完成");
        medicalAppointment.setUpdateTime(new Date());
        boolean update=medicalAppointmentService.updateById(medicalAppointment);
        if(update==true){
            return R.ok().data("ok","修改成功");
        }else {
            return R.ok().data("error","修改失败");
        }
    }

}

